package com.Inter.T03;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {
        // 客户端：发一条数据，接收服务端的信息并打印
        // 服务端：接手数据并打印，在给客户端反馈信息

        // 1.创建socket对象
        Socket socket = new Socket("127.0.0.1", 10000);

        // 2.写数据
        OutputStream os = socket.getOutputStream();
        String str = "你好呀！";
        os.write(str.getBytes());
        // 写出一个结束标记
        socket.shutdownOutput();

        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        int b;
        while ((b = br.read()) != -1) {
            System.out.print((char) b);
        }

        // 3.s释放资源
        socket.close();
    }
}
